package com.aistar.service.impl;

import com.aistar.mapper.DynamicCollectMapper;
import com.aistar.pojo.DynamicCollect;
import com.aistar.pojo.DynamicCollectExample;
import com.aistar.service.DynamicCollectService;
import com.aistar.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DynamicCollectServiceImpl implements DynamicCollectService {
    private final DynamicCollectMapper dynamicCollectMapper;

    @Autowired
    public DynamicCollectServiceImpl(DynamicCollectMapper dynamicCollectMapper) {
        this.dynamicCollectMapper = dynamicCollectMapper;
    }

    @Override
    public ServerResponse getByCidAndPid(Integer customerId, Integer dynamicId) {
        DynamicCollectExample example = new DynamicCollectExample();
        example.createCriteria()
                .andCustomerIdEqualTo(customerId)
                .andDynamicIdEqualTo(dynamicId);
        List<DynamicCollect> dynamicCollectList = dynamicCollectMapper.selectByExample(example);
        if (dynamicCollectList != null && dynamicCollectList.size() > 0)
            return ServerResponse.getSuccess(dynamicCollectList.get(0));
        return ServerResponse.getFailed();
    }


}
